package foodmaterial.utils;

import java.math.BigDecimal;
import java.text.DecimalFormat;

public class Arithmetic {
    private static DecimalFormat df = new DecimalFormat("#.00");
    public static BigDecimal add(BigDecimal value1,BigDecimal value2,int scale){
        return value1.add(value2).setScale(scale, BigDecimal.ROUND_HALF_UP);
    }

    public static BigDecimal add(BigDecimal value1,Integer value2,int scale){
        return value1.add(new BigDecimal(value2.toString())).setScale(scale, BigDecimal.ROUND_HALF_UP);
    }

    public static BigDecimal sub(BigDecimal value1,BigDecimal value2){
        return value1.subtract(value2).setScale(2, BigDecimal.ROUND_HALF_UP);
    }

    public static BigDecimal mul(BigDecimal value1,BigDecimal value2,int scale){
        return value1.multiply(value2).setScale(scale, BigDecimal.ROUND_HALF_UP);
    }

    public static BigDecimal mul(BigDecimal value1,Integer value2,int scale){
        return value1.multiply(new BigDecimal(value2.toString())).setScale(scale, BigDecimal.ROUND_HALF_UP);
    }

    public static BigDecimal div(BigDecimal value1,BigDecimal value2,int scale) {
        if(scale<0){
            throw new RuntimeException("精确度不能小于0");
        }
        return value1.divide(value2, scale , BigDecimal.ROUND_HALF_UP);
    }

    public static BigDecimal div(BigDecimal value1,Integer value2,int scale) {
        return div(value1,new BigDecimal(value2.toString()),scale) ;
    }

    public static boolean up(double d) {
        if (d % 1 >= 0.09) return true;
        return false ;
    }

}
